package cn.csxw.openchina.dagger2.presenter;

import java.util.ArrayList;

import javax.inject.Inject;

import cn.csxw.openchina.entity.bean.ActiveBean;
import cn.csxw.openchina.entity.bean.OsChinaBean;
import cn.csxw.openchina.ui.fragment.myMessageFragment.MyMessageFragment;
import retrofit2.Call;

/**
 *我--》消息---》@我
 */

public class MyMessageFragmentPresenter extends BasePresenter {
    MyMessageFragment mMyMessageFragment;
    private ArrayList<ActiveBean> mActivies;
    @Inject
    public MyMessageFragmentPresenter(MyMessageFragment myMessageFragment) {
        mMyMessageFragment = myMessageFragment;
    }

    @Override
    protected void processData(OsChinaBean data) {
        if (data!=null){
            mActivies = (ArrayList<ActiveBean>) data.activies;
            if (mMyMessageFragment.mAdapter.getData()!= null&&
                    mMyMessageFragment.mAdapter.getData().size()!=0){
                mMyMessageFragment.mAdapter.addData(mActivies);
            }else {
                mMyMessageFragment.mAdapter.setData(mActivies);
            }
            mMyMessageFragment.loadMoreCompleted();
            mMyMessageFragment.mSrfLayout.setRefreshing(false);
        }
    }

    @Override
    public void callNetWork(Object... params) {
        if(params.length!=4||!(params[0] instanceof String)
                ||!(params[1] instanceof Integer)||!(params[2]
                instanceof Integer)||!(params[3] instanceof Integer)){
            throw new IllegalArgumentException("参数必需是String,int ," +
                    " int ,int,四个类型，在消息中@我中");
        }
        Call<OsChinaBean> activeInfo = mOsChinaServer.getActiveInfo((String) params[0],
                (int) params[1], (int) params[2], (int) params[3]);
        activeInfo.enqueue(mCallback);

    }
}
